//总共消耗了1420毫秒
package beach;

import utils.JDBCutils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Insert_Offcn_Demo2 {
    public static void main(String[] args) throws SQLException {
        Connection con = JDBCutils.getConnection();
        String s = "insert  into offcn values (?,?,?,?)";
        PreparedStatement ps = con.prepareStatement(s);
        long start = System.currentTimeMillis();
        for (int i = 1; i <=100000 ; i++) {
            ps.setInt(1,i+1);
            ps.setString(2,"ztt" + i +"zz");
            ps.setInt(3,i+20);
            ps.setString(4,"zt" + i + "@qq.com");
            //积攒
            ps.addBatch();
            if (i%2000 == 0 ){
                System.out.println("插了" + i + "下") ;
                //批量插入
                ps.executeBatch();
            }
        }
        long end = System.currentTimeMillis();
        System.out.println("总共消耗了" + (end - start) + "毫秒");
        //清除批量插入
        ps.clearBatch();
        ps.close();
        con.close();
    }

}
